import { Context, Session } from 'koishi'
import { getGalPathOfIndex_API } from '../axios/api/gal'

export default class qqMessage {
    private channelId: string;
    private session: Session;
    private qq: any;

    constructor(session: Session) {
        this.channelId = session.event.channel.id;
        this.session = session;
        this.qq = session.qq;
    }

    public init() {
        const { session } = this;
        let text = session.content;
        text = text.substring(text.indexOf('>') + 2, text.length).trim();

        if (text.indexOf('<img') != -1) {
            // 含有图片
        } else {
            // 文字消息
            const actionName = text.split(' ')[0];
            console.log(this, actionName, text);
            this[actionName](text);
        }

    }

    //#region action

    //请求gal从index
    public get(text: string) {
        const arr = text.split(' ');
        if (arr.length != 2) {
            this.send('get 指令输入错误, 格式案例: [get a0001]');
        } else {
            getGalPathOfIndex_API({
                id: arr[1]
            }).then(res => {
                console.log(res)
            }).catch(res => {
                console.log(res)
            })

            this.send('这是' + arr[1] + '!');
        }

    }
    //#endregion

    public send(text: string) {
        const { channelId, qq } = this;
        qq.sendMessage(channelId, {
            content: text,
            msg_type: 0,
        });
    }

}